package com.example.demo1.insurance;
import java.util.Scanner;
public class Baoxian3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入你的姓名：");
        String name = sc.next();
        int age = age();// 年龄
        String sex = sex();// 性别
        String marry = marry();// 婚姻
        int money = money();// 投保金额
        int salary = salary();// 抚养人数
        float baofei = bo(age, sex, marry, salary, money);
        System.out.println("参保人:" + name + "的保费是：" + baofei);
    }

    public static int age() {
        Scanner sc = new Scanner(System.in);
        System.out.print("你的年龄是：");
        int age = sc.nextInt();
        if (age > 120 || age < 0) {
            System.out.println("您输入的年纪有误，请重新输入：");
            age();
        }
        return age;
    }

    public static String sex() {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入性别（男性，女性）：");
        String sex = sc.next();
        switch (sex) {
            case "男性":
                break;
            case "女性":
                break;
            default:
                System.out.println("您输入的性别有误，请重新输入");
                sex();
                break;
        }
        return sex;
    }

    public static String marry() {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入您的婚姻状况（已婚或者未婚）：");

        String marry = sc.next();
        switch (marry) {
            case "已婚":

                break;
            case "未婚":
                break;
            default:
                System.out.println("您输入的婚姻状况有误，请重新输入（已婚或者未婚）：");
                marry();
                break;
        }
        return marry;
    }

    //抚养人数
    public static int salary() {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入您抚养人数：");
        int salary = sc.nextInt();
        if (salary > 7 || salary < 0) {
            System.out.println("您输入的抚养人数有误,请重新输入：");
            salary();
        }
        return salary;
    }

    // 输入投保金额
    public static int money() {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入投保金额：");
        int money = sc.nextInt();
        if (money < 0) {
            System.out.println("您输入的金额有误,请重新输入：");
            money();
        }
        return money;
    }

    private static float bo(int age, String sex, String marry, int salary, int money) {
        int count = 0;
        // 判断年纪
        if (age > 20 && age < 39) {
            count += 6;
        } else if (age > 40 && age < 59) {
            count += 4;
        } else {
            count += 2;
        }

        // 判断性别
        if (sex.equals("男性")) {
            count += 5;
        } else if (sex.equals("女性")) {
            count += 3;
        }

        // 判断婚姻状况
        if (marry.equals("已婚")) {
            count += 3;
        } else if (marry.equals("未婚")) {
            count += 5;
        }

        // 判断抚养人数
        switch (salary) {
            case 0:

                break;
            case 1:
                count -= 0.5;
                break;
            case 2:
                count -= 0.5;
                break;
            case 3:
                count -= 0.5;
                break;
            case 4:
                count -= 0.5;
                break;
            case 5:
                count -= 0.5;
                break;
            case 6:
                count -= 0.5;
                break;
            default:
                break;
        }

        // 将点数四舍五入
        int counts = Math.round(count);

        // 根据点数判断
        if (counts >= 10) {
            return (float) (money * 0.006);
        } else {
            return (float) (money * 0.001);
        }
    }
}